package com.qk.management.controller;

import com.qk.constant.ClueConstant;
import com.qk.dto.clue.ClueDTO;
import com.qk.dto.clue.ClueQueryDTO;
import com.qk.dto.clue.MarkFalseClueDTO;
import com.qk.entity.Clue;
import com.qk.management.service.ClueService;
import com.qk.result.PageResult;
import com.qk.result.Result;
import com.qk.vo.clue.CluePoolQueryVO;
import com.qk.vo.clue.ClueQueryVO;
import com.qk.vo.clue.ClueVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:zhengbowen
 * @Date: 2025/10/10 19:36
 * @Description: 线索管理控制器
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/clues")
@RequiredArgsConstructor
public class ClueController {

    private final ClueService clueService;

    @PutMapping("/false/{id}")
    public Result falseDeleteClue(@PathVariable Integer id, @RequestBody MarkFalseClueDTO markFalseClueDTO) {
        clueService.falseDeleteClue(id,markFalseClueDTO);
        return Result.success();
    }

    @GetMapping("/pool")
    public Result listCluesInPool(ClueQueryDTO clueQueryDTO) {
        PageResult<CluePoolQueryVO> pageResult = clueService.listCluesInPool(clueQueryDTO);
        return Result.success(pageResult);
    }

    @PutMapping("/toBusiness/{id}")
    public Result convertToBusiness(@PathVariable Integer id) {
        clueService.convertToBusiness(id);
        return Result.success();
    }

    @PutMapping
    public Result trackClue(@RequestBody ClueDTO clueDTO) {
        clueService.trackClue(clueDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueById(@PathVariable Integer id) {
        ClueVO ClueVO = clueService.getClueById(id);
        return Result.success(ClueVO);
    }

    @PutMapping("/assign/{clueId}/{userId}")
    public Result assignClue(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateByClueId(clueId,userId);
        return Result.success();
    }

    @PostMapping
    public Result insertClue(@RequestBody Clue clue) {
        clueService.insert(clue);
        return Result.success();
    }

    @GetMapping
    public Result listClues(ClueQueryDTO clueQueryDTO) {
        PageResult<ClueQueryVO> pageResult = clueService.listClues(clueQueryDTO);
        return Result.success(pageResult);
    }

}